import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/***
    //不用setbuluder
 ***/
class AnimalWidget extends StatefulWidget {
  final String ?text;

  AnimalWidget({this.text}) : super();

  @override
  State<StatefulWidget> createState() {
    return _AnimalState();
  }
}

class _AnimalState extends State<AnimalWidget>
    with SingleTickerProviderStateMixin {
  AnimationController ?_controller;
  Animation<Color> ?_colorAnimation;
  Animation<Size> ?_sizeAnimation;

  @override
  void initState() {
    super.initState();
    _controller =
        AnimationController(vsync: this, duration: Duration(seconds: 2));

    _colorAnimation =
        ColorTween(begin: Colors.blue, end: Colors.red).animate(_controller as Animation<double>) as Animation<Color>?;
    _sizeAnimation =
        SizeTween(begin: Size(100.0, 50.0), end: Size(200.0, 100.0))
            .animate(_controller as Animation<double>) as Animation<Size>?;
    _controller?.forward();
    _controller?.addStatusListener((status) {
      if(status==AnimationStatus.completed){
         _controller?.reverse();
      }else if(status==AnimationStatus.dismissed){
        _controller?.forward();
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.text??""),
      ),
      body: Center(
        child: Column(
          children: [
            SizedBox(
              height: 30,
            ),
            AnimatedBuilder(
              animation: _controller!,
              builder: (context, widget) {
                return Container(
                  width: _sizeAnimation?.value.width,
                  height: _sizeAnimation?.value.height,
                  color: _colorAnimation?.value,
                );
              },
            ),
          ],
        ),
      ),
    );
  }

  @override
  void dispose() {
    _controller?.dispose();
    super.dispose();
  }
}
